import request from '../utils/request';
import { API } from '../utils/config';

/**
 * 获取商品列表
 * @param params 查询参数
 */
export const getProductList = (params: any) => {
  return request({
    url: `${API.CLASSES}/Product`,
    method: 'GET',
    params
  });
};

/**
 * 获取商品详情
 * @param id 商品ID
 */
export const getProductDetail = (id: string) => {
  return request({
    url: `${API.CLASSES}/Product/${id}`,
    method: 'GET'
  });
};

/**
 * 创建商品
 * @param data 商品数据
 */
export const createProduct = (data: any) => {
  return request({
    url: `${API.CLASSES}/Product`,
    method: 'POST',
    data
  });
};

/**
 * 更新商品
 * @param id 商品ID
 * @param data 商品数据
 */
export const updateProduct = (id: string, data: any) => {
  return request({
    url: `${API.CLASSES}/Product/${id}`,
    method: 'PUT',
    data
  });
};

/**
 * 删除商品
 * @param id 商品ID
 */
export const deleteProduct = (id: string) => {
  return request({
    url: `${API.CLASSES}/Product/${id}`,
    method: 'DELETE'
  });
};

/**
 * 商品上架
 * @param id 商品ID
 */
export const shelfProduct = (id: string) => {
  return updateProduct(id, { sellingStatus: 'onShelf' });
};

/**
 * 商品下架
 * @param id 商品ID
 */
export const unshelfProduct = (id: string) => {
  return updateProduct(id, { sellingStatus: 'offShelf' });
};

/**
 * 获取商品分类列表
 */
export const getCategoryList = () => {
  return request({
    url: `${API.CLASSES}/Category`,
    method: 'GET'
  });
};

/**
 * 获取商品品牌列表
 */
export const getBrandList = () => {
  return request({
    url: `${API.CLASSES}/Brand`,
    method: 'GET'
  });
};

/**
 * 获取商品分组列表
 */
export const getGroupList = () => {
  return request({
    url: `${API.CLASSES}/Group`,
    method: 'GET'
  });
};

/**
 * 保存商品草稿
 * @param data 商品数据
 */
export const saveProductDraft = (data: any) => {
  data.isDraft = true;
  return createProduct(data);
};

/**
 * 获取商品草稿列表
 */
export const getProductDrafts = () => {
  return request({
    url: `${API.CLASSES}/Product`,
    method: 'GET',
    params: {
      isDraft: true
    }
  });
};

/**
 * 导出商品数据
 * @param ids 商品ID数组
 */
export const exportProducts = (ids: string[]) => {
  return request({
    url: '/functions/exportProducts',
    method: 'POST',
    data: { ids }
  });
}; 